package com.fcl.blog.service.impl;

import com.fcl.blog.exception.ServiceException;
import com.fcl.blog.mapper.TypeMapper;
import com.fcl.blog.po.Type;
import com.fcl.blog.po.TypeTop;
import com.fcl.blog.service.TypeService;
import com.fcl.blog.vo.TypeVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.TransactionAnnotationParser;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.List;

/**
 * @Author 付
 * @Date 2023/10/22 14:43
 * @Version 1.0
 * @description  分类的业务层实现
 * @since 1.0
 */
@Service
@Slf4j
public class TypeServiceImpl implements TypeService {
    @Autowired
    private TypeMapper typeMapper;

    @Override
    public List<Type> findListType() {
        return typeMapper.findListType();
    }

    @Transactional
    @Override
    public int insertType(Type type) {
        return typeMapper.insertType(type);
    }

    @Override
    public Type selectByName(String name) {
        return typeMapper.selectByName(name);
    }


    @Transactional
    @Override
    public int deleteById(Long id) {
        return typeMapper.deleteById(id);
    }

    @Transactional(rollbackFor = ServiceException.class)
    @Override
    public int updateByType(TypeVo type) {
        try {
            return typeMapper.updateByType(type);
        } catch (Exception e) {
            log.error("抱歉，查询问题出错"+e);
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().isRollbackOnly();
            return 0;
        }
    }

    @Override
    public Type selectById(Long id) {
        return typeMapper.selectById(id);
    }

    @Override
    public List<TypeTop> typeTop() {
        return typeMapper.typeTop();
    }

    @Override
    public Long total() {
        return typeMapper.total();
    }

    @Override
    public List<TypeTop> typeTopAll() {
        return typeMapper.typeTopAll();
    }
}
